package com.ruoyi.examEthnicity.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.examEthnicity.domain.ExamEthnicity;
import com.ruoyi.examEthnicity.service.IExamEthnicityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "基础管理-民族信息")
@RestController
@RequestMapping("/ethnicity")
public class ExamEthnicityController {

    @Autowired
    private IExamEthnicityService ethnicityService;

    /**
     * 查询民族列表
     */
                @ApiOperation("民族管理 - 分页查询列表")
    @GetMapping("/list")
    public AjaxResult list() {
        List<ExamEthnicity> ethnicities = ethnicityService.selectEthnicityList();
        return AjaxResult.success(ethnicities);
    }

    /**
     * 根据ID获取民族信息
     */
                @ApiOperation("民族管理 - 根据ID获取详细信息")
    @GetMapping("/info")
    public AjaxResult getInfo(@RequestParam Long id) {
        ExamEthnicity ethnicity = ethnicityService.selectEthnicityById(id);
        return ethnicity != null ? AjaxResult.success(ethnicity) : AjaxResult.error("民族信息不存在");
    }

    /**
     * 新增民族信息
     */
                @ApiOperation("民族管理 - 新增数据")
    @PostMapping
    public AjaxResult add(@RequestBody ExamEthnicity ethnicity) {
        int rows = ethnicityService.insertEthnicity(ethnicity);
        return rows > 0 ? AjaxResult.success("新增成功") : AjaxResult.error("新增失败");
    }

    /**
     * 修改民族信息
     */
                @ApiOperation("民族管理 - 修改数据")
    @PutMapping
    public AjaxResult edit(@RequestBody ExamEthnicity ethnicity) {
        int rows = ethnicityService.updateEthnicity(ethnicity);
        return rows > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败");
    }

    /**
     * 删除民族信息
     */
                @ApiOperation("民族管理 - 删除数据")
    @DeleteMapping
    public AjaxResult remove(@RequestParam Long[] ids) {
        int rows = ethnicityService.deleteEthnicityByIds(ids);
        return rows > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
}
